//
//  FoodDetailViewController.m
//  dogGroup
//
//  Created by iOS Two on 14-8-25.
//  Copyright (c) 2014年 iOS Two. All rights reserved.
//

#import "FoodDetailViewController.h"

@interface FoodDetailViewController ()

@end

@implementation FoodDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated {
    [MobClick beginLogPageView:@"FoodDetailViewController"];
}
-(void)viewDidDisappear:(BOOL)animated {
    [self clearAllUIWebViewData];
    [MobClick endLogPageView:@"FoodDetailViewController"];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    if (![self netWorkCheck]) {
        [self alertViewShow:@"网络未连接"];
    }
    if (version >= 7) {
        self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.13 green:0.76 blue:0.86 alpha:1];
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
        titleLabel.text = _foodTitle;
        titleLabel.font = [UIFont systemFontOfSize:20];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor whiteColor];
        self.navigationItem.titleView = titleLabel;
    } else {
        self.navigationItem.title = _foodTitle;
        self.navigationController.navigationBar.tintColor =[UIColor colorWithRed:0.13 green:0.76 blue:0.86 alpha:1];
    }
    UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(webReload)];
    self.navigationItem.rightBarButtonItem = button;
    
    _web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, kHeight - 64)];
    if (version >= 7) {
        
    } else {
        _web.frame = CGRectMake(0, 0, 320, kHeight - 44);
    }
    NSString *str = [[NSString alloc]init];
    NSRange range = [_url rangeOfString:@"tmall"];
    if (range.length >0) {
        str = [NSString stringWithFormat:@"%@",_url];
    } else {
        str = [NSString stringWithFormat:@"http://gate.baidu.com/tc?from=opentc&src=%@",_url];
    }
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:str]];
    [_web loadRequest:request];
    _web.delegate = self;
    _web.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_web];
    // Do any additional setup after loading the view.
}
-(void)webReload {
    [_web reload];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//当webview开始加载的时候调用
- (void)webViewDidStartLoad:(UIWebView *)webView {
    [self showIndeterminateProgress];
}

//当webView结束加载的时候调用
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    //隐藏菊花圈
    [HUD hide:YES];
}

@end
